package LeetCode;

import java.util.LinkedList;
import java.util.Queue;

public class AnimalAdopt0306 {
}
class AnimalShelf {

    Queue<int[]> dogs, cats;

    public AnimalShelf() {
        dogs = new LinkedList<>();
        cats = new LinkedList<>();
    }

    public void enqueue(int[] animal) {
        if (animal[1] == 0) {
            cats.add(animal);
        } else {
            dogs.add(animal);
        }
    }

    public int[] dequeueAny() {
        if (dogs.isEmpty() && cats.isEmpty()) return new int[]{-1, -1};
        else if (dogs.isEmpty()) return cats.poll();
        else if (cats.isEmpty()) return dogs.poll();
        else if (dogs.peek()[0] < cats.peek()[0]) return dogs.poll();
        else return cats.poll();
    }

    public int[] dequeueDog() {
        if (dogs.isEmpty()) return new int[]{-1, -1};
        return dogs.poll();
    }

    public int[] dequeueCat() {
        if (cats.isEmpty()) return new int[]{-1, -1};
        return cats.poll();
    }
}

